home *** CD-ROM | disk | FTP | other *** search
- Path: soap.news.pipex.net!pipex!usenet
- From: gs94@dial.pipex.com
- Newsgroups: comp.lang.c++
- Subject: Which is better????
- Date: Sun, 24 Mar 1996 14:01:02 +0000
- Organization: UnipalmPIPEX server (post doesn't reflect views of UnipalmPIPEX)
- Message-ID: <3155559E.7120@dial.pipex.com>
- NNTP-Posting-Host: an164.du.pipex.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
- CC: c.mackay@dcs.napier.ac.uk
-
- I have a project where data is passed between functions, as is fairly normal in a
- C++ program. What I would like to know is:
-
- Which is better / faster, passing data by pointers or by reference, e.g.
-
- void main()
- {
- CMyObject theObject;
-
- // Perform function 1 (uses pointer)
- function_1(&theObject);
-
- // Perform function 2 (uses reference)
- function_2(theObject);
- }
-
- void function_1( CMyObject* pMyObject )
- {
- pMyObject->DoSomethingWithObject();
- }
-
- void function_2( CMyObject& MyObject )
- {
- MyObject.DoSomethingWithObject();
- }
-
-
- I would prefer to use the faster method as I am iterating over some functions
- several times passing megabytes of data (not all at once, in chunks of a few
- dozen bytes at a time)
-
- What is the real difference between the two methods also?
-
- Thanks,
-
-
- Colin Mackay - gs94@dial.pipex.com
-